const express = require('express');
const ejs = require('ejs')
// 获取文档对象
const newModel = require('./db/model/newsModel')
const app = express();
app.listen(80,()=>{
    console.log("服务启动成功80");
})
// app.set('views',__dirname+'/html')
// app.engine('html',ejs.renderFile)
// 路由
app.get('/',(req,res)=>{
    newModel.find().then(val=>{
        res.render('index.ejs',{val})
    })
})
app.get('/detail/:id',(req,res)=>{
    let {id} = req.params;
    newModel.find().then(arr=>{
        let {title,content} = arr.find(item=>item.id==id);
        res.render('detail.ejs',{title,content})
    })  
})